﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Win8Start.UI
{
	public partial class FolderPanel : ShortcutPanel
	{
		public FolderPanel()
		{
			InitializeComponent();
		}

		private List<string> _folderList = new List<string>();
		public List<string> FolderList
		{
			get { return _folderList; }
		}

		/// <summary>
		/// Show a folder in the window without overwriting the saved list of items
		/// </summary>
		/// <param name="FolderName"></param>
		protected virtual void ShowFolder(string FolderName)
		{
			if (FolderName == null || FolderName == "")
				return;

			Clear();
			string f = Path.GetFullPath(FolderName);
			foreach (string fi in FolderList)
			{
				if (f == fi)
				{
					ReloadAll();
					return;
				}
			}

			if (Directory.Exists(FolderName))
			{
				AddItem(FolderName + "\\..");
				LoadFolder(FolderName);
				ShowList();
				return;
			}

			MessageBox.Show("Could not load folder: " + FolderName);
		}

		protected override void mi_MouseClick(object sender, MouseEventArgs e)
		{
			MenuItemControl mi = sender as MenuItemControl;

			if (mi != null)
			{
				if (mi.Shortcut.IsFolder)
				{
					ShowFolder(mi.Shortcut.FileName);
				}
				else
				{
					base.mi_MouseClick(sender, e);
				}
			}

		}

		public override void  ReloadAll()
		{
			foreach (string folder in FolderList)
			{
				string path = Environment.ExpandEnvironmentVariables(folder);
				LoadFolder(path);
			}
			base.ReloadAll();
		}

	}
}
